﻿@{
    ViewBag.Title = "物资收费项目对照";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="panel panel-default">
    <div style="padding-right:10px;">
        <table class="form">
            <tr>
                <td class="formValue" style="width: 160px;">
                    <div class="btn-group">
                        <a class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新建</a>
                    </div>
                    <div class="btn-group">
                        <a class="btn btn-primary" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
                    </div>
                    <div class="btn-group">
                        <a class="btn btn-primary" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除</a>
                    </div>
                </td>
                <th class="formTitle">收费大类：</th>
                <td class="formValue">
                    <select class="form-control" id="selSfdl">
                        <option value="">==全部==</option>
                    </select>
                </td>
                <th class="formTitle">物资类型：</th>
                <td class="formValue">
                    <select class="form-control" id="selProductType">
                        <option value="">==全部==</option>
                    </select>
                </td>
                <th class="formTitle" style="width: 50px;">状态：</th>
                <td class="formValue" style="width: 60px;">
                    <select class="form-control" id="selZt">
                        <option value="">=全部=</option>
                        <option value="1">有效</option>
                        <option value="0">作废</option>
                    </select>
                </td>
                <td class="formValue">
                    <div class="btn-group" id="dv_search">
                        <a class="btn btn-primary"><span class="fa fa-search"></span></a>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<script lang="javascript">

    var $gridList = $("#gridList");
    $(function () {
        gridList();
        Init();
    });

    //初始化
    function Init() {
        //加载项目大类
        $("#selSfdl").bindSelect({
            url: "/ProductManage/ProductSfxm/GetAllSfdl"
        });
        //加载物资类别
        $("#selProductType").bindSelect({
            url: "/ProductManage/ProductType/GetPatientTreeSelectJson"
        });
    }


    //get data
    function gridList() {
        $gridList.dataGrid({
            url: "/ProductManage/ProductSfxm/GetProductSfxmGridJson",
            postData: getPostData(),
            height: $(window).height() - 125,
            colModel: [
                { label: "主键", name: "Id", hidden: true, key: true },
                { label: "项目大类", name: "sfdlmc", width: 100, align: "left" },
                { label: "项目名称", name: "sfxmmc", width: 100, align: "left" },
                { label: "物资类别", name: "productTypeName", width: 100, align: "left" },
                { label: '物资名称', name: 'productName', width: 100, align: 'left' },
                {
                    label: "有效", name: "zt", width: 50, align: "center",
                    formatter: function (cellvalue) { return cellvalue === "1" ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>"; }
                },
                { label: '创建人', name: 'CreatorCode', width: 70, align: 'left' },
                { label: '创建时间', name: 'CreateTime', width: 110, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i', newformat: 'Y-m-d H:i' } },
                { label: '最后修改', name: 'LastModifierCode', hidden: true },
                { label: '最后修改时间', name: 'LastModifyTime', hidden: true }
            ],
            pager: "#gridPager",
            sortname: 'CreateTime desc',
            viewrecords: true
        });
        $("#dv_search").click(function () {
            $gridList.jqGrid('setGridParam',
                {
                    postData: getPostData()
                }).trigger('reloadGrid');
        });
    }

    //组装请求参数
    function getPostData() {
        return {
            sfdlCode: $("#selSfdl").val(),
            productTypeId: $("#selProductType").val(),
            zt: $("#selZt").val()
        };
    }

    //回车触发查询事件
    $(document).keyup(function (event) {
        if (event.keyCode === 13) {
            $("#dv_search").trigger("click");
        }
    });

    //新增
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增",
            url: "/ProductManage/ProductSfxm/Form",
            width: "550px",
            height: "310px",
            callBack: function (iframeId) {
                $.currentWindow(iframeId).AcceptClick(function () {
                    $('#gridList').jqGrid("clearGridData"); //清除明细的grid
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                });
            }
        });
    }

    //修改
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        if (!!!keyValue) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        $.modalOpen({
            id: "Form",
            title: "修改",
            url: "/ProductManage/ProductSfxm/Form?keyValue=" + keyValue,
            width: "550px",
            height: "310px",
            callBack: function (iframeId) {
                $.currentWindow(iframeId).AcceptClick(function () {
                    $('#gridList').jqGrid("clearGridData"); //清除明细的grid
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                });
            }
        });
    }

    //删除
    function btn_delete() {
        $.modalConfirm("您确定要将删除该关联吗？",
            function (flag) {
                if (flag) {
                    var keyValue = $("#gridList").jqGridRowValue().Id;
                    if (!!!keyValue) {
                        $.modalAlert("请选中一条信息", 'warning');
                        return;
                    }
                    $.najax({
                        url: "/ProductManage/ProductSfxm/DeleteForm",
                        data: { keyValue: keyValue },
                        dataType: "json",
                        success: function (data) {
                            if (data.state === "success") {
                                $('#gridList').jqGrid("clearGridData"); //清除明细的grid
                                $("#gridList").resetSelection();
                                $("#gridList").trigger("reloadGrid");
                            } else {
                                if (data.state != null) {
                                    $.modalMsg(data.state, 'warning', 1500);
                                } else {
                                    $.modalMsg("删除失败", 'warning', 1500);
                                }
                            }
                        }
                    });
                }
            });
    }

</script>
